#pragma once

#include<iostream>
#include<cstdio>
#include<cassert>
#include<unistd.h>
#include<cstring>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<fcntl.h>
#include"Log.hpp"

using namespace std;

#define PATH_NAME "/home/clh"
#define PROJ_ID 0x66
#define SHM_SIZE 4096

#define FIFO_NAME "./fifo"

class Init
{
public:
    Init()
    {
        umask(0);
        int n = mkfifo(FIFO_NAME,0666);
        assert(n == 0);
        (void)n;
        Log("create fifo success",Notice)<<"\n";
    }
    ~Init()
    {
        unlink(FIFO_NAME);
        Log("remove fifo success",Notice)<<"\n";
    }
};

#define READ O_RDONLY
#define WRITE O_WRONLY
int OpenFIFO(std::string pathname,int flags)
{
    int fd = open(pathname.c_str(),flags);
    assert(fd>=0);
    return fd;
}

void Wait(int fd)
{
    Log("等待中...",Notice)<<"\n";
    uint32_t temp = 0;
    ssize_t s = read(fd,&temp,sizeof(uint32_t));
    assert(s == sizeof(uint32_t));
    (void)s;
}

void Signal(int fd)
{
    Log("唤醒中...",Notice)<<"\n";
    uint32_t temp = 1;
    ssize_t s = write(fd,&temp,sizeof(uint32_t));
    assert(s == sizeof(uint32_t));
    (void)s;
}

void closeFifo(int fd)
{
    close(fd);

}